#代码加速技巧
# 使用Numba加速数值计算
from numba import jit
import numpy as np

@jit(nopython=True)
def monte_carlo_pi(n_samples):
    acc = 0
    for _ in range(n_samples):
        x = np.random.random()
        y = np.random.random()
        if (x**2 + y**2) < 1.0:
            acc += 1
    return 4.0 * acc / n_samples

print(monte_carlo_pi(10_000_000))

#并发处理方案

# 多进程处理CPU密集型任务
from multiprocessing import Pool

def process_chunk(data):
    # 数据处理逻辑
    return sum(data)

if __name__ == '__main__':
    data = [range(1,1000000)] * 8
    with Pool(4) as p:
        results = p.map(process_chunk, data)
    total = sum(results)